package com.mxx.common.data.jpa;

import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 * @Author itzgyw
 * @Date 2020-01-08
 * @Time 15:53
 * @Description:
 */
@FunctionalInterface
public interface LambdaSpec<T> extends Specification<T> {

    @Override
    default Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
        return this.helper(new LambdaSpecHelper<T>(root, criteriaBuilder, criteriaQuery));
    }

    Predicate helper(LambdaSpecHelper<T> helper);

}
